package com.baizhi.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 用来测试属性注入
 */
@RestController
public class InjectionController {

    @Value("${name}")
    private String name;

    @Value("${age}")
    private Integer age;

    @Value("${price}")
    private Double price;

    @Value("${birthday}")
    private Date birthday;

    @Value("${sex}")
    private Boolean sex;

    @Value("${qqs}")
    private String[] qqs;

    @Value("${lists}")
    private List<String> lists;

    @Value("${sets}")
    private Set<String> sets;

    @Value("#{${maps}}")    // 注入时必须使用 ”#{${xxx}}“ 进行获取
    private Map<String, Object> maps;

    @RequestMapping("inject")
    public String inject() {
        System.out.println("inject ok");
        System.out.println("name = " + name);
        System.out.println("age = " + age);
        System.out.println("price = " + price);
        System.out.println("birthday = " + birthday);
        System.out.println("sex = " + sex);
        System.out.println("qqs = " + Arrays.toString(qqs));
        System.out.println("lists = " + lists);
        System.out.println("sets = " + sets);
        System.out.println("maps = " + maps);
        return "inject ok";
    }
}
